package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * 地区
 */
@Getter
@Setter
public class Region extends BaseDomain{
    //禁用
    public static final Integer STATE_DISABLE = -1;
    //普通
    public static final Integer STATE_COMMON = 0;
    //热门
    public static final Integer STATE_HOT = 1;

    //名称
    private String name;
    //上级地区
    private Region parent;
    //状态
    private Integer state = 0;

    public Map toTreeMap(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("text",name);
        map.put("lazyLoad",true);
        if (state==STATE_HOT){
            map.put("tags",new String[]{"推荐"});
        }
        return map;
    }

    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        if (parent!=null){
            map.put("parentId",parent.getId());
            map.put("parentName",parent.getName());
        }
        map.put("state",state);
        return JSON.toJSONString(map);
    }
}